﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BabyFood.Entities;
using BabyFood.Data;
using System.Data;

public partial class ChiTietSachhay : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Params["IdSach"] != null)
        {
            H_SachId.Value = Request.Params["IdSach"].ToString();
            View_Sach(Convert.ToInt32(H_SachId.Value));
        }
        HienThiLoaiTin();
        //Pager1.CurrentIndex = 1;
        //Bind_Data(Pager1.CurrentIndex);
    }

    protected void View_Sach(int IdSach)
    {
        SachHay entSach = DataRepository.SachHayProvider.GetById(IdSach);
        try
        {
            if (entSach != null)
            {
                int TotalRows = 0;
                //TList<CommentSachHay> TList_TinTucs = DataRepository.CommentSachHayProvider.GetPaged("IdSachHay = " + Convert.ToInt32(H_SachId.Value), "", 0, 0, out TotalRows);
                // Retrieve the Parent List
                //lblComment.Text = TotalRows.ToString();

                int ChiaSe = 0;
                //TList<ThichSachHay> TList_Thich = DataRepository.ThichSachHayProvider.GetPaged("IdSachHay = " + Convert.ToInt32(H_SachId.Value), "", 0, 0, out ChiaSe);
                // Retrieve the Parent List

                //lblChiaSe.Text = ChiaSe.ToString();
                lblTenSach.Text = entSach.TenSach;
                littieude.Text = entSach.TenSach;
                lblTenSachtop.Text = entSach.TenSach;
                lblTheLoai.Text = entSach.TheLoai;
                lblNhaXuatBan.Text = entSach.TenNhaXuatBan;
                lblHinhThuc.Text = entSach.HinhThucBia;
                //lblNoiDungTin.Text = Server.HtmlDecode(entSach.DienGiai);
                lblNgayXuatBan.Text = Common.StandardStringjquery(entSach.NgayCapNhat.ToString("dd/MM/yyyy"));
                lblTacGia.Text = entSach.TacGia;
                lblSoTrang.Text = entSach.SoTrang.ToString();
                lblKichThuoc.Text = entSach.KichThuoc;
                lblNoiDungTin.Text = Server.HtmlDecode(entSach.NoiDung);
                lbltrongLuong.Text = entSach.TrongLuong;
                lblGiaBia.Text = entSach.GiaBan.ToString("###,##0");
                Image1.ImageUrl = entSach.AnhDaiDien.ToString();
                Session["Title"] = entSach.TenSach;
                H_TieuDe.Value = entSach.TenSach;

            }
        }
        catch (Exception ex) { }
    }

    protected void cmdFacebook_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            Response.Redirect("http://www.facebook.com/sharer.php?u=" + HttpContext.Current.Request.Url.AbsolutePath);
        }
        catch (Exception ex)
        { }
    }
    protected void cmdTwiter_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            Response.Redirect("http://twitter.com/home?status=" + HttpContext.Current.Request.Url.AbsolutePath);
        }
        catch (Exception ex)
        { }
    }
    protected void cmdYahoo_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            Response.Redirect("ymsgr:im?+&msg=Xem bài này hay lắm nè: " + HttpContext.Current.Request.Url.AbsolutePath);
        }
        catch (Exception ex)
        { }
    }
    protected void cmdEmail_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            Response.Redirect("https://mail.google.com/mail/?view=cm&fs=1&to&su=" + H_TieuDe.Value + "&body=" + HttpContext.Current.Request.Url.AbsolutePath + "%23.TwF6mDNohJo.gmail&ui=2&tf=1&shva=1");
        }
        catch (Exception ex)
        { }
    }
    protected void cmdZing_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            Response.Redirect("http://link.apps.zing.vn/share?u=" + HttpContext.Current.Request.Url.AbsolutePath + "&images=&media=&width=0&height=0");
        }
        catch (Exception ex)
        { }
    }
    protected void cmdSend_Click(object sender, ImageClickEventArgs e)
    {
        bool updateStatus = false;
        try
        {            
        }
        catch (Exception ex)
        {
            Common.WriteLog("ChiTietSachHay.aspx.cs", "cmdSend_Click", ex.ToString());
            WebMessage.Show("Cập nhật Comment thất bại!");
        }
    }

    /// <summary>
    /// Bind Comment
    /// </summary>
    /// <param name="PageNo"></param>
    //protected void Bind_Data(int PageNo)
    //{
    //    try
    //    {
    //        //facebook.NavigateUrl = "http://www.facebook.com/sharer.php?u=" + Common.sPathUpLienKet + "/TinTucND.aspx?Id="+ H_CatalogId.Value.ToString();
    //        //twiter.NavigateUrl = "http://twitter.com/home?status=" + Common.sPathUpLienKet + "/TinTucND.aspx?Id="+ H_CatalogId.Value.ToString();
    //        //zingme.NavigateUrl = "http://wb.me.zing.vn/index.php?wb=" + Common.sPathUpLienKet + "/TinTucND.aspx?Id=" + H_CatalogId.Value.ToString() + "&t=js&c=share_button";
    //        int TotalRows = 0;
    //        string WhereClause = "1=1 and IdSachHay=" + H_SachId.Value + "";
    //        DataSet dsSachHay = DataRepository.Provider.ExecuteDataSet("CommentSachHay_GetPaged", WhereClause, "NgayCapNhat DESC", PageNo - 1, Pager1.PageSize);
    //        //dlcomment.DataSource = dsSachHay.Tables[0];
    //        //dlcomment.DataBind();
    //        try
    //        {
    //            TotalRows = Convert.ToInt32(dsSachHay.Tables[1].Rows[0][0]);
    //        }
    //        catch (Exception)
    //        {
    //        }
    //        //Pager1.ItemCount = TotalRows;
    //        //if (TotalRows <= Pager1.PageSize)
    //        //    Pager1.Visible = false;
    //        //else
    //        //    Pager1.Visible = true;
    //    }
    //    catch (Exception)
    //    {
    //    }
    //}

    //protected void Pager1_Command(object sender, CommandEventArgs e)
    //{
    //    int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
    //    Pager1.CurrentIndex = currnetPageIndex;
    //    Bind_Data(currnetPageIndex);
    //}

    /// <summary>
    /// Hiển thị Loại tin
    /// </summary>
    private void HienThiLoaiTin()
    {
        int TotalRows = 0;
        TList<SachHay> TList_TinTuc = DataRepository.SachHayProvider.GetPaged("", "NgayCapNhat DESC", 0, 3, out TotalRows);
        dlLoaiTinTuc.DataSource = TList_TinTuc;
        dlLoaiTinTuc.DataBind();
    }

    public string GetLienKet()
    {
        return Common.sPathUpLienKet;
    }

    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }

    public string GetNgay(object ngayviet)
    {
        DateTime s = Convert.ToDateTime(ngayviet);
        string v = s.ToString("dd/MM/yyyy");
        return Common.StandardStringjquery(v);
    }
}